import api from '@/http/api.js';
import util from '@/http/util.js';
export default {
	data() {
		return {
			BaseUrl:getApp().globalData.apiUrl,
			formData: {
				bank_type_id:'',//支付方式
				qrcode: '', // 实际项目中替换为二维码图片URL
				alipayAccount: '13178174444',
				alipayName: '黄俊',
				bankName: '建行',
				accountOpeningArea: '', //开户地区
				accountOpeningBranch: '', //开户网点
				city: '北京市/东城区',
				nickname: '习惯很晚睡',
				dailyOrders: '100',
				concurrentOrders: '3'
			},

			choosePayId: "", //渠道id
			choosePayName: "", //渠道名称

			showCityPicker: false,
			cities: [{
					name: "北京市",
					cities: ["东城区", "西城区", "朝阳区", "丰台区", "石景山区", "海淀区", "门头沟区", "房山区", "通州区"]
				},
				{
					name: "天津市",
					cities: ["和平区", "河东区", "河西区", "南开区", "河北区", "红桥区", "东丽区", "西青区"]
				},
				{
					name: "河北省",
					cities: ["石家庄市", "唐山市", "秦皇岛市", "邯郸市", "邢台市", "保定市", "张家口市", "承德市"]
				}
			]
		};
	},
	onLoad(data) {
		console.log(data)
		if (data) {
			this.choosePayId = data.id;
			this.choosePayName = data.name;
		}
		try{
			let that = this;
			uni.getStorage({
				key:'edit',
				success(res) {
					console.log(res.data)
					that.formData.bank_type_id = res.data.id,
					that.formData.qrcode = res.data.qr_code,
					that.formData.alipayAccount = res.data.bank_card,
					that.formData.alipayName = res.data.real_name,
					that.formData.bankName = res.data.bank_name,
					that.formData.accountOpeningArea = res.data.bank_area,
					that.formData.accountOpeningBranch = res.data.bank_branch,
					that.formData.nickname = res.data.nickname,
					that.formData.dailyOrders = res.data.one_day_order,
					that.formData.concurrentOrders = res.data.tong_shi_order
					uni.removeStorage({
						key: 'edit'
					});
				}
			})
		}catch(e){
			console.log(e)
		}
	},
	methods: {
		//上传图片
		uploadPictures() {
			let that = this;
			uni.chooseImage({
				count: 1,
				sizeType: ['compressed'],
				sourceType: ['album'],
				success: function(res) {
					uni.uploadFile({
						url: 'https://4pay.dt12.cfd/api/common/upload',
						filePath: res.tempFilePaths[0],
						header: {
							'token': util.getToken(),
						},
						success(res) {
							let newres = JSON.parse(res.data)
							if (newres.code == 1) {
								that.formData.qrcode = newres.data.url
								uni.showToast({
									title: '上传成功'
								})
							}else{
								uni.showToast({ title: res.msg, icon: 'none' });
							}
						},
						fail(err) {
							uni.showToast({
								title: '上传失败',
								icon: 'error'
							})
						}
					})
				}
			})
		},
		// selectCity(province, city) {
		//   this.formData.city = `${province}/${city}`;
		//   this.showCityPicker = false;
		// },

		saveAccount() {
			
			api.editPaymentMethod({
				"bank_id": this.formData.bank_type_id,
				// "bank_name": this.formData.bankName,
				"bank_area": this.formData.accountOpeningArea,
				// "bank_branch": this.formData.accountOpeningBranch,
				// "bank_card": this.formData.alipayAccount,
				// "real_name": this.formData.alipayName,
				// "qr_code": this.formData.qrcode,
				"nickname": this.formData.nickname,
				"one_day_order": this.formData.dailyOrders,
				"tong_shi_order": this.formData.concurrentOrders
			}).then(res => {
				if (res.code == 1) {
					uni.showToast({
						title: '账号信息保存成功',
						icon: 'success'
					});
					// uni.navigateBack({
					// 	delta: 1
					// })
				}else{
					uni.showToast({ title: res.msg, icon: 'none' });
				}
			}).catch(err => {

			})
		}
	}
};